package com.oracle.lingshangejia.dialog;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.activity.ArchivesActivity;
import com.oracle.lingshangejia.mvp.base.BaseDialogFragment;

import java.util.Calendar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @松 on 2019/10/31 13:30
 * 添加随访
 */
public class AddVisitRecordDialog extends BaseDialogFragment {
    @BindView(R.id.tv_service)
    TextView mTvService;
    @BindView(R.id.tv_start)
    TextView mTvStart;
    @BindView(R.id.tv_end)
    TextView mTvEnd;
    @BindView(R.id.tv_patient)
    TextView mTvPatient;
    Unbinder unbinder;
    private String mServire ="";//
    private String start;
    private String end;

    @Override
    public int setLayoutId() {
        return R.layout.dialog_visit_record;
    }

    @Override
    protected void initWindow(Window window) {
        setLayoutParams(window, Gravity.CENTER, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, 0, 0);

    }



    @Override
    protected void initData(View view) {
        super.initData(view);
        unbinder = ButterKnife.bind(this, view);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.tv_service, R.id.tv_start, R.id.tv_end, R.id.tv_patient, R.id.et_remark, R.id.btn_cancel, R.id.btn_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_service://专项
                new MaterialDialog.Builder(getContext())
                    .title("专项服务")
                    .positiveText("确认")
                    .items(R.array.nation_archives)
                    .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
                        @Override
                        public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                            if (!TextUtils.isEmpty(text)) {

                            }

                            return true;
                        }
                    })
                    .show();

                break;
            case R.id.tv_start://开始时间
                showDate(1, mTvStart);
                break;
            case R.id.tv_end://结束时间
                showDate(0, mTvEnd);
                break;
            case R.id.tv_patient://患者
                break;
            case R.id.et_remark:////备注
                break;
            case R.id.btn_cancel://取消
                dismiss();
                break;
            case R.id.btn_confirm://确定
                break;
        }
    }


    //显示日期
    public void showDate(int i, TextView v) {
        Calendar calendar;
        DatePickerDialog dialog;
        calendar = Calendar.getInstance();
        dialog = new DatePickerDialog(getContext(),
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year,
                                      int monthOfYear, int dayOfMonth) {
                    System.out.println(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
                    String month;
                    String day;
                    if (monthOfYear <9){
                        month = "0"+(monthOfYear+1);
                    }else {
                        month = ""+(monthOfYear+1);
                    }
                    if (dayOfMonth <10){
                        day = "0"+dayOfMonth;
                    }else {
                        day = dayOfMonth + "";
                    }
                    System.out.println("后"+year + "-" + month  + "-" + day);
                    String date = year + "-" + month + "-" + day;
                    if (i==1) {
                        start =date;
                        v.setText("开始日期："+start);
                    }else {
                        end =date;
                        v.setText("结束日期："+end);
                    }

                }

            }, calendar.get(Calendar.YEAR), calendar
            .get(Calendar.MONTH), calendar
            .get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }



}
